<template>
	<view>
		<view class="ddress-choose-box" v-if="JSON.stringify(address) === '{}'">
			<button class="addAdderssBtn" type="primary" @click="chooseAddress">请选择收货地址+</button>
		</view>
		<!-- 收货信息 -->
		<view class="ddress-info-box" v-else  @click="chooseAddress">
			<view class="left">
				<view class="addressInfo-top">
					<view class="topInfo-left">收货人：{{address.userName}}</view>
					<view class="topInfo-right">电话：{{address.telNumber}}</view>
				</view>
				<view class="addressInfo-bottom">
					<view>收货地址：{{addStr}}</view>
				</view>
			</view>
			<view class="right">
				<uni-icons type="arrowright" size="16"></uni-icons>
			</view>
		</view>
		<!-- 底部的边框线 -->
		<view class="line-view"></view>
	</view>
</template>

<script>
	import {mapState,mapMutations,mapGetters} from 'vuex'
	
	export default {
		name:"my-adress",
		data() {
			return {
				noAddresFlag: true,
				// address:{}
			};
		},
		computed:{
			...mapState('m_user',['address']),
			...mapGetters('m_user',['addStr'])
			
		},
		onLoad() {
			console.log('~~~~~',this.address)
		},
		methods:{
			...mapMutations('m_user',['updateAddress']),
			async chooseAddress() {
			    const [err,succ] = await uni.chooseAddress({
					
				}).catch(err => err)
				
				if(err === null && succ.errMsg == 'chooseAddress:ok'){
					console.log(succ)
					// this.address = succ
					this.updateAddress(succ)
				}
				//用户没有授权 则让用户先去授权
				if (err && err.errMsg === 'chooseAddress:fail auth deny') {
					this.reAuth()
				}
			}
		}
	}
</script>

<style lang="scss">
	.ddress-choose-box{
		height: 60px;
		padding: 10px;
		display: flex;
		justify-content: center;
		padding-bottom: 10px;
		align-items: center;
		.addAdderssBtn{
			color: white;
			background-color: #C00000;
			font-size: 15px;
			width: 200px;
			height: 40px;
			align-items: center;
		}
	}
	.ddress-info-box{
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10px;
		.left{
			margin-right: 10px;
			width: 720rpx;
			.addressInfo-top{
				display: flex;
				justify-content: space-between;
				margin-bottom: 10px;
				.topInfo-left{
					font-size: 15px;
				}
				.topInfo-right{
					font-size: 15px;
				}
			}
			.addressInfo-bottom{
				font-size: 15px;
			}
		}
		.right{
			width: 30rpx;
		}
	}
	
	
	.line-view{
		height: 5px;
		border-bottom: 5px dashed #efefef;
	}
</style>
